package fel.via.cz.thewolfofwallstreet.components;

import android.app.Activity;
import android.util.Log;
import android.widget.TabHost;

import org.json.JSONException;
import org.json.JSONObject;

import fel.via.cz.thewolfofwallstreet.R;
import fel.via.cz.thewolfofwallstreet.enums.AppViewState;

public class ShareInfoTabHost {

    private TabHost tabHost;
    private ShareInfoView shareInfoView;
    private ShareGraphView shareGraphView;
    private ShareNewsView shareNewsView;

    public ShareInfoTabHost(Activity activity) {
        this.tabHost = (TabHost) activity.findViewById(R.id.thInformations);
        this.shareInfoView = new ShareInfoView(activity);
        this.shareGraphView = new ShareGraphView(activity);
        this.shareNewsView = new ShareNewsView(activity);
        this.initialize();
    }

    private void initialize() {
        this.tabHost.setup();

        TabHost.TabSpec infoTab = tabHost.newTabSpec("InfoTab");
        infoTab.setIndicator("Info");
        infoTab.setContent(R.id.Info);

        TabHost.TabSpec graphTab = tabHost.newTabSpec("GraphTab");
        graphTab.setIndicator("Graph");
        graphTab.setContent(R.id.Graph);

        TabHost.TabSpec newsTab = tabHost.newTabSpec("NewsTab");
        newsTab.setIndicator("News");
        newsTab.setContent(R.id.News);

        this.tabHost.addTab(infoTab);
        this.tabHost.addTab(graphTab);
        this.tabHost.addTab(newsTab);
    }

    public void setTabsContent(JSONObject company, AppViewState viewState, double userMoney) {
        this.shareInfoView.setup(company, viewState, userMoney);
        try {
            this.shareGraphView.setup(company.getString("name"), this.shareNewsView);
        } catch (JSONException e) {
            Log.e("ShareInfoTabHost", "Parsing company name");
        }
    }

    public void disabledControls() {
        this.shareInfoView.disabledControls();
    }
}
